import type {RequestClientOptions} from '../types';
import qs from 'qs';

import {isString} from '#/utils';

const getParamsSerializer = (paramsSerializer: RequestClientOptions['paramsSerializer']) => {
    if (isString(paramsSerializer)) {
        switch (paramsSerializer) {
            case 'brackets': {
                return (params: any) =>
                    qs.stringify(params, {arrayFormat: 'brackets'});
            }
            case 'comma': {
                return (params: any) => qs.stringify(params, {arrayFormat: 'comma'});
            }
            case 'indices': {
                return (params: any) =>
                    qs.stringify(params, {arrayFormat: 'indices'});
            }
            case 'repeat': {
                return (params: any) => qs.stringify(params, {arrayFormat: 'repeat'});
            }
        }
    }
    return paramsSerializer;
};

export {getParamsSerializer};